home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9929 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  47 lines

  1. Path: news.netins.net!trg1
  2. From: hhowe@trgnet.com (Harold Howe)
  3. Newsgroups: comp.lang.c++
  4. Subject: Encapsulation question.
  5. Date: Tue, 05 Mar 96 00:59:35 GMT
  6. Organization: Technology Resource Group
  7. Message-ID: <4hg701$goi@insosf1.netins.net>
  8. NNTP-Posting-Host: desm-22-14.dialup.netins.net
  9. X-Newsreader: News Xpress Version 1.0 Beta #3
  10.  
  11. Greetings. 
  12.  
  13. Does the following violate encapsulation?  Should an object tell a private 
  14. member the address of other private members?  I am using this on a grander 
  15. scale, in which the Application class tells a private dialog object the 
  16. address of a private configuration structure?  The dialog class needs access 
  17. to the structure so it can modify it, and this is how I tell the dialog where 
  18. to look.  Aside from using globals, does anyone have any better suggestions?
  19.  
  20. class Application
  21.   {
  22.   private:
  23.     int j;
  24.     Dialog *dlg;
  25.   public:
  26.     Application(void)  { dlg = new Dialog(&j);  }
  27.   }
  28.  
  29. class Dialog
  30.   {
  31.   private:
  32.     int *ptr;
  33.     ... // plus other members which access ptr
  34.   public:
  35.     Dialog(int *addr) {  ptr = addr } ;
  36.   }
  37.  
  38. int main()
  39.   {
  40.   Application app;
  41.   }
  42.  
  43.  
  44. Thanks
  45. Harold Howe
  46. hhowe@trgnet.com 
  47.